package com.example.admin.config;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.Collection;

/**
 * @author wang wei
 * @description
 * @create 2021/9/28 15:14
 */
@Component
public class CustomResourcesValid {
   public boolean exec(String s) {
      SecurityContext context = SecurityContextHolder.getContext();
      Authentication authentication = context.getAuthentication();
      Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
      for (GrantedAuthority authority : authorities) {
         String authority1 = authority.getAuthority();
         if (authority1.equals(s)) {
            return true;
         }
      }
      return false;
   }
}
